Fix unused TimeoutStrategy parameter #823
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The issue or feature being addressed
Fix the
timeoutStrategy
parameter not being used byPolicy.TimeoutAsync<TResult>(Func<TimeSpan>, TimeoutStrategy, Func<Context, TimeSpan, Task, Task>)
which meant thatTimeoutStrategy.Optimistic
was always being used.I found this issue when experimenting with whether it was worth adding a
net5.0
TFM to Polly (TL;DR - I don't think it is) and enabling the new .NET analyzers built into the .NET 5.0 SDK. Doing that flagged up the unused parameter as a CA1801 warning.Details on the issue fix or feature implementation
Pass the parameter value to
Policy.TimeoutAsync<TResult>(Func<Context, TimeSpan>, TimeoutStrategy, Func<Context, TimeSpan, Task, Task>)
.I did try to come up with a unit test that verified the wrong strategy was being used pre-fix, but I got stuck with the custom clock implementation in the tests and couldn't get a test using a never-completing callback to not hang forever.
Confirm the following